package com.jswj.word.controller;

import java.util.List;

import com.jswj.word.domain.WordExt;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.jswj.word.domain.Word;
import com.jswj.word.service.IWordService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 关键词Controller
 *
 * @author whh
 * @date 2021-06-26
 */
@Controller
@RequestMapping("/screenshot/word")
public class WordController extends BaseController {
    private String prefix = "screenshot/word";

    @Autowired
    private IWordService wordService;

    @RequiresPermissions("screenshot:word:view")
    @GetMapping()
    public String word() {
        return prefix + "/word";
    }

    /**
     * 查询关键词列表
     */
    @RequiresPermissions("screenshot:word:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Word word) {
        startPage();
        List<WordExt> list = wordService.selectWordList(word);
        return getDataTable(list);
    }

    /**
     * 导出关键词列表
     */
    @RequiresPermissions("screenshot:word:export")
    @Log(title = "关键词", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Word word) {
        List<WordExt> list = wordService.selectWordList(word);
        ExcelUtil<WordExt> util = new ExcelUtil<WordExt>(WordExt.class);
        return util.exportExcel(list, "关键词数据");
    }

    /**
     * 新增关键词
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存关键词
     */
    @RequiresPermissions("screenshot:word:add")
    @Log(title = "关键词", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Word word) {
        return toAjax(wordService.insertWord(word));
    }

    /**
     * 修改关键词
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        Word word = wordService.selectWordById(id);
        mmap.put("word", word);
        return prefix + "/edit";
    }

    /**
     * 修改保存关键词
     */
    @RequiresPermissions("screenshot:word:edit")
    @Log(title = "关键词", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Word word) {
        return toAjax(wordService.updateWord(word));
    }

    /**
     * 删除关键词
     */
    @RequiresPermissions("screenshot:word:remove")
    @Log(title = "关键词", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(wordService.deleteWordByIds(ids));
    }
}
